<?php
?>
<header class="panel-heading">
	<strong> Danh Mục Hàng Hóa Dịch Vụ </strong>
</header>
<div class="panel-body">
	<div class="adv-table editable-table ">
		<div class="clearfix">
			<form id="frmaddHanghoadv" class="form-horizontal tasi-form" method="get">
			  	<input type="hidden" name="idHanghoadv" id="idHanghoadv" value="-1" />			  	
				<div class="form-group" id="grpten">
					<label class="col-sm-2 col-sm-2 control-label">Tên hàng hóa</label>
					<div class="col-sm-10">
						<input name="Ten" id="Ten" type="text" class="form-control" />
                    </div>
				</div>
				<div class="form-group" id="grpmavach">					
                    <label class="col-sm-2 col-sm-2 control-label">Mã vạch</label>
					<div class="col-sm-10">
						<input name="MaVach" id="MaVach" type="text" class="form-control" />
                    </div>                    
				</div>
				<div class="form-group" id="grpgiamua">					
                    <label class="col-sm-2 col-sm-2 control-label">Giá mua</label>
					<div class="col-sm-10">
						<input name="GiaMua" id="GiaMua" type="text" class="form-control" />
                    </div>                    
				</div>
				<div class="form-group" id="grpgiaban">					
                    <label class="col-sm-2 col-sm-2 control-label">Giá Bán</label>
					<div class="col-sm-10">
						<input name="GiaBan" id="GiaBan" type="text" class="form-control" />
                    </div>
				</div>
				<div class="form-group" id="grpDonViTinh">
					<label class="col-sm-2 control-label">Đơn vị tính</label>
					<div class="col-sm-10">                                          
                           <select class="form-control m-bot15" name ="DonViTinh" id ="DonViTinh">
                           	   <option value ="-1"> Chọn đơn vị tính...</option>
                               <?php foreach ($this->rsDonvitinh as $donvitinh) {?> 
                                  <option value ="<?php echo $donvitinh['Id']?>" > <?php echo $donvitinh['Ten']?></option>                                   
                               <?php } ?>
                            </select>                                          
                    </div>
				</div>
				<div class="form-group" id="grpNhomHang">
					<label class="col-sm-2 control-label">Nhóm hàng</label>
					<div class="col-sm-10">                                          
                         <select class="form-control m-bot15" name = "NhomHang" id ="NhomHang">
                                 <option value = "-1"> Chọn nhóm hàng.. </option>
                                 <?php foreach ($this->rsNhomhhdv as $nhomhhdv){?>
                                 	<option value = "<?php echo $nhomhhdv['Id']?>"> <?php echo $nhomhhdv['Ten']?></option>
                                 <?php  }?>
                                 </select>                                          
                    </div>                   
				</div>	
				<div class = "form-group" id = "grphinhanh">
					<label class="col-sm-2 col-sm-2 control-label">Hình ảnh</label>
                    <div class="col-sm-10">
                         <div class="fileupload fileupload-new" data-provides="fileupload"><input type="hidden">                              
                               <div>
                                    <span class="btn btn-white btn-file">                                    
                                    <input name = "DuongDanAnh" class="default" id="DuongDanAnh" type="file">
                                    </span>
                                    <a href="#" class="btn btn-danger fileupload-exists" data-dismiss="fileupload"><i class="icon-trash"></i> Remove</a>
                              </div>
                          </div>                         
                    </div>
				</div>
				
				<div class="form-group">
					<label class="col-sm-2 col-sm-2 control-label">Ngưng sử dụng</label>
					<div class="col-sm-10">
						<input name="TrangThai" type="checkbox" checked="" data-toggle="switch" />
					</div>
				</div>
			</form>
			  <div class="modal-footer">
			  	<button data-dismiss="modal" class="btn btn-default" type="button">Đóng</button>
			  	<button class="btn btn-success" type="button" id="luuthaydoi">Lưu thay đổi</button>
			  	<button class="btn btn-success" type="button">Lưu & Thêm mới</button>
		  	  </div>
		</div>
	</div>
</div>
			  
			  
<script>
jQuery(document).ready(function() {
	  EditableTable.init();
	  
	  
	  jQuery("#luuthaydoi").click(function(){

		var values = $('#frmaddHanghoadv').serialize();
		
		if($('#Ten').val()=="")
		  {
			  $('#grpten').addClass("has-error");
			  alert("Vui lòng nhập tên hàng hóa");
			  $('#Ten').focus();
			  return;
		  }

		  if($('#DonViTinh').val()=="-1")
		  {
			$('grpDonViTinh').addClass("has-error");
			alert("Vui lòng chọn đơn vị tính");
			$('#DonViTinh').focus();
			return;
		  }
		  
		  if($('#NhomHang').val()=="-1")
		  {
			$('grpNhomHang').addClass("has-error");
			alert("Vui lòng chọn nhóm hàng");
			$('#DonViTinh').focus();
			return;
		  }
		  
		  var saveUrl = "<?php echo _BASE_URL?>/quantri/hanghoadv/save";		   

		  var oTable = $('#editable-sample').dataTable();
		  
		  $.ajax({
			  url : saveUrl,
			  type: "POST",
			  
			  data: values,
			  success: function(data, textStatus, jqXHR)
			  {
				  alert("Đã lưu thành công!");
				  location.href= "<?php echo _BASE_URL?>quantri/hanghoadv";
				  $(".btn-default").click();
			  },
			  error: function (jqXHR, textStatus, errorThrown)
			  {
				  alert('That bai');
			  }
			});
	  });
});

</script>
